/*
 * IBM Corporation.
 * Copyright (c) 2014 All Rights Reserved.
 */

package com.ibm.risk.gdb.cinda.web;

import java.util.Locale;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.HierarchicalMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.ibm.iisp.common.web.springmvc.ExposedResourceBundleMessageSource;

/**
 * 类作用：
 * 
 * @author JohnnyZhou@cn.ibm.com 使用说明：
 */
@Controller
public class HomeController {
	@Resource
	HierarchicalMessageSource messageSource;

	@RequestMapping("/assets/commonjs")
	public String commonjs(HttpServletRequest request, HttpServletResponse response, Model model) {
		Locale locale = RequestContextUtils.getLocale(request);
		Set<Object> mkeys = ((ExposedResourceBundleMessageSource) messageSource).getKeys(locale);
		String envName = System.getProperty("envName");
		model.addAttribute("envName", envName);
		String contextPath = System.getProperty("contextPath");
		if (contextPath == null) {
			contextPath = request.getContextPath();
		}
		model.addAttribute("contextPath", contextPath);
		model.addAttribute("mkeys", mkeys);
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/javascript");
		return "/commonjs.ftl";
	}
}
